package com.tyz.hellocst.entity;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Person {
    private String userName = new String();
    private String userMd5 = new String();
    private String userPwd = new String();
    private String userNum = new String();
    private String name = new String();
    private String sex = new String();

    public Person() {

    }

    public Person(String userName, String userPwd, String userNum,String name, String sex) {
        this.userName = userName;
        this.userPwd = userPwd;
        this.userNum = userNum;
        this.name = name;
        this.sex = sex;
        this.userMd5 = md5(userName);
    }

    public void setUserName(String userName) {
        this.userName = userName;
        this.userMd5 = md5(userName);
    }

    public String getUserNum() {
        return userNum;
    }

    public void setUserNum(String userNum) {
        this.userNum = userNum;
    }

    public String getUserName() {
        return userName;
    }

    public String getUserMd5() {
        return userMd5;
    }

    public void setUserPwd(String userPwd) {
        this.userPwd = userPwd;
    }

    public String getUserPwd() {
        return userPwd;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getSex() {
        return sex;
    }

    public boolean isEmpty() {
        return userMd5.isEmpty();
    }

    private String md5(String string) {
        if (string.isEmpty()) {
            return "";
        }
        MessageDigest md5 = null;
        try {
            md5 = MessageDigest.getInstance("MD5");
            byte[] bytes = md5.digest(string.getBytes());
            String result = "";
            for (byte b : bytes) {
                String temp = Integer.toHexString(b & 0xff);
                if (temp.length() == 1) {
                    temp = "0" + temp;
                }
                result += temp;
            }
            return result;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
}

